package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.component.DataLabelsComponent;
import com.zygh.policeasset.pojo.DataLabels;
import com.zygh.policeasset.service.DataLabelsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/dataLabels"})
@Api(tags = {"数据标签管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/DataLabelsController.class */
public class DataLabelsController {
    @Autowired
    DataLabelsService dataLabelsService;
    @Autowired
    DataLabelsComponent dataLabelsComponent;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("新增")
    public Object add(@RequestBody DataLabels dataLabels) {
        if (this.dataLabelsService.add(dataLabels).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "数据标签主键", required = true, paramType = "query")})
    @ApiOperation("删除")
    public Object delete(@RequestBody JSONObject json) {
        if (this.dataLabelsService.delete(json.getInteger("id")).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/updateName"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "数据标签主键", required = true, paramType = "query"), @ApiImplicitParam(name = "name", value = "数据标签名称", required = true, paramType = "query")})
    @ApiOperation("修改名称")
    public Object updateName(@RequestBody JSONObject json) {
        if (this.dataLabelsService.update(json.getString("name"), null, json.getInteger("id")).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/updateToEnable"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "数据标签主键", required = true, paramType = "query")})
    @ApiOperation("修改数据标签启用")
    public Object updateToEnable(@RequestBody JSONObject json) {
        if (this.dataLabelsService.updateToEnable().intValue() == 0) {
            return new CommonResult().validateFailed("修改失败");
        }
        Integer count1 = this.dataLabelsService.update(null, 1, json.getInteger("id"));
        this.dataLabelsComponent.init();
        if (count1.intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/selectList"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有")
    public Object selectList(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.dataLabelsService.selectList(pageNum, pageSize);
    }

    @RequestMapping(value = {"/findAll"}, method = {RequestMethod.GET})
    @ApiOperation("查询所有")
    public Object findAll() {
        return this.dataLabelsService.findAll();
    }

    @RequestMapping(value = {"/selectById"}, method = {RequestMethod.GET})
    @ApiOperation("根据ID查询")
    public Object selectById(@RequestParam Integer id) {
        return this.dataLabelsService.selectById(id);
    }
}